

package com.hazelcast.scheduledexecutor.impl;

import java.util.concurrent.RejectedExecutionException;

/**
 * A capacity controller that keeps track of task counts upon scheduling/disposing and Rejects tasks accordingly
 */
public interface CapacityPermit {

    /**
     * Acquires a permit to schedule a new task.
     * When max allowance is reached, future attempts will trigger a {@link RejectedExecutionException} exception
     *
     * @throws RejectedExecutionException
     */
    void acquire() throws RejectedExecutionException;

    /**
     * Acquires a permit to schedule a new task.
     * When max allowance is reached, future attempts will silently keep acquiring permits without any exceptions
     */
    void acquireQuietly();

    /**
     * Releases a permit back to pool for future use
     */
    void release();

    /**
     * @return the total number of acquired permits
     */
    int totalAcquired();
}
